#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
LL arr[N];
int n, k;
bool check(LL x)
{
	LL ans = 0;
	LL sum = 1;
	for (int i = 1; i <= n; i++) {
		/*if (ans + arr[i] * arr[i] <= x) {
			ans += arr[i] * arr[i];
		}
		else {
			sum++;
			ans = arr[i] * arr[i];
		}*/
		if (ans + arr[i] * arr[i] > x)ans = 0, sum++;
		ans += arr[i] * arr[i];
	}
	return sum <= k;
}
int main()
{
	cin >> n >> k;
	LL l = 0, r = 0;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		l = max(l, arr[i]*arr[i]);
		r += (LL)arr[i] * arr[i];
	}
	l--, r++;
	while (l + 1 < r) {
		LL mid = l + r >> 1;
		if (check(mid))r = mid;
		else l = mid;
	}
	cout << r << endl;
	return 0;
}